/**
 * 初始化报考专业详情对话框
 */
var EnrollSchoolBatchMajorInfoDlg = {
    enrollSchoolBatchMajorInfoData : {},
    validateFields : {
    	majorCode : {
			validators : {
				notEmpty : {
					message : '报考专业代号不能为空'
				},
				stringLength : {
					max : 50,
					message : '报考学校代号长度不能超过50'
				}
			}
		},
		majorName : {
			validators : {
				notEmpty : {
					message : '报考专业名称不能为空'
				},
				stringLength : {
					max : 50,
					message : '报考学校名称长度不能超过50'
				}
			}
		},
        schoolLength : {
            validators : {
                stringLength : {
                    max : 20,
                    message : '专业学制长度不能超过20'
                }
            }
        }
	}
};

/**
 * 清除数据
 */
EnrollSchoolBatchMajorInfoDlg.clearData = function() {
    this.enrollSchoolBatchMajorInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
EnrollSchoolBatchMajorInfoDlg.set = function(key, val) {
    this.enrollSchoolBatchMajorInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
EnrollSchoolBatchMajorInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
EnrollSchoolBatchMajorInfoDlg.close = function() {
    parent.layer.close(window.parent.EnrollSchoolBatchMajor.layerIndex);
}

/**
 * 收集数据
 */
EnrollSchoolBatchMajorInfoDlg.collectData = function() {
    this
    .set('id')
    .set('enrollSchoolId')
    .set('majorCode')
    .set('majorName')
    .set("schoolLength")
    .set('batchType',$("#batchType").select2("val"));
}

/**
 * 提交添加
 */
EnrollSchoolBatchMajorInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();
    if (!this.validate()) {
		return;
	}
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/enrollSchoolBatchMajor/add", function(data){
        Feng.success("添加成功!");
        window.parent.EnrollSchoolBatchMajor.table.refresh();
        EnrollSchoolBatchMajorInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.enrollSchoolBatchMajorInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
EnrollSchoolBatchMajorInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();
    if (!this.validate()) {
		return;
	}
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/enrollSchoolBatchMajor/update", function(data){
        Feng.success("修改成功!");
        window.parent.EnrollSchoolBatchMajor.table.refresh();
        EnrollSchoolBatchMajorInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.enrollSchoolBatchMajorInfoData);
    ajax.start();
}

/**
 * 验证数据是否为空
 */
EnrollSchoolBatchMajorInfoDlg.validate = function() {
	$('#enrollSchoolBatchMajorInfoForm').data("bootstrapValidator").resetForm();
	$('#enrollSchoolBatchMajorInfoForm').bootstrapValidator('validate');
	return $("#enrollSchoolBatchMajorInfoForm").data('bootstrapValidator').isValid();
};

$(function() {
	Feng.initValidator("enrollSchoolBatchMajorInfoForm", EnrollSchoolBatchMajorInfoDlg.validateFields);
});
